package com.example.back.service;

import com.example.back.entity.Chat;
import com.example.back.mapper.ChatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;

@Service
public class ChatService {
    LocalDateTime currentDateTime = LocalDateTime.now() .truncatedTo(ChronoUnit.MINUTES);
    @Autowired
    private  ChatMapper chatMapper;


    public int addChat(Chat chat)
        {
            LocalDateTime currentDateTime = LocalDateTime.now();
            chat.setTime(currentDateTime.toString());
            System.out.println("当前时间: " + currentDateTime.toString());
            return chatMapper.addChat(chat);
        }
        public int deleteChat(Integer id)
        {
            return chatMapper.deleteChat(id);
        }
        public int updateChat(Chat chat)
        {
            return chatMapper.updateChat(chat);
        }
        public Chat queryChatById(Integer id)
        {
            return chatMapper.queryChatById(id);
        }
        public ArrayList<Chat> queryChat(Chat chat)
        {
            return chatMapper.queryChat(chat);
        }
        public ArrayList<Chat> queryChatText(Integer fszId, Integer jszId){
        return chatMapper.queryChatText(fszId, jszId);
    }
}
